USE [dbdata]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[fk_user_categ_id]') AND parent_object_id = OBJECT_ID(N'[dbo].[users]'))
ALTER TABLE [dbo].[users] DROP CONSTRAINT [fk_user_categ_id]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__users__categ_id__78D28677]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[users] DROP CONSTRAINT [DF__users__categ_id__78D28677]
END

GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF__users__dt__79C6AAB0]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[users] DROP CONSTRAINT [DF__users__dt__79C6AAB0]
END

GO

USE [dbdata]
GO

/****** Object:  Table [dbo].[users]    Script Date: 04/08/2012 23:24:33 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[users]') AND type in (N'U'))
DROP TABLE [dbo].[users]
GO

USE [dbdata]
GO

/****** Object:  Table [dbo].[users]    Script Date: 04/08/2012 23:24:43 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[users](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[categ_id] [int] NOT NULL,
	[dt] [datetime] NOT NULL,
	[dt_locked] [smalldatetime] NULL,
	[comment] [nvarchar](max) NULL,
	[name] [varchar](50) NULL,
PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[users]  WITH CHECK ADD  CONSTRAINT [fk_user_categ_id] FOREIGN KEY([categ_id])
REFERENCES [dbo].[user_categs] ([id])
GO

ALTER TABLE [dbo].[users] CHECK CONSTRAINT [fk_user_categ_id]
GO

ALTER TABLE [dbo].[users] ADD  DEFAULT ((1)) FOR [categ_id]
GO

ALTER TABLE [dbo].[users] ADD  DEFAULT (getdate()) FOR [dt]
GO

